﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharepointSolutionInstaller.Views;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Data.SqlClient;
using SharepointSolutionInstaller.Utils.Log;

namespace SharepointSolutionInstaller.Utils.SolutionDeployment
{
    public abstract class FeatureCommand : Command
    {
        protected FeatureCommand(InstallProcess parent) : base(parent) { }
        protected static readonly Logger log = Logger.messageCollector();
        // Modif JPI - Début
        protected static void DeactivateFeature(List<Guid?> featureIds)
        {
            try
            {
                if (featureIds != null && featureIds.Count > 0)
                {
                    foreach (Guid? featureId in featureIds)
                    {
                        if (featureId != null)
                        {
                            SPFeature feature = SPWebService.AdministrationService.Features[featureId.Value];
                            if (feature != null)
                            {
                                SPWebService.AdministrationService.Features.Remove(featureId.Value);
                            }
                        }
                    }
                }
            }

            catch (ArgumentException ex)  // Missing assembly in GAC
            {
                //     log.Warn(ex.Message, ex);
            }

            catch (InvalidOperationException ex)  // Missing receiver class
            {
                //  log.Warn(ex.Message, ex);
            }

            catch (SqlException ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
        // Modif JPI - Fin
    }
}
